package com.luoying.itew.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.luoying.itew.R;

/**
 * Created by lyk on 2017/5/19.
 */

public class MySliderView extends FrameLayout {

    private TextView[] contents;
    private View[] slides;

    private int[] ids={R.id.item1, R.id.item2, R.id.item3, R.id.item4, R.id.item5, R.id.item6,};


    public MySliderView(Context context) {
        super(context);
    }

    public MySliderView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public MySliderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context)
    {
        contents=new TextView[ids.length];
        slides=new View[ids.length];
        View slideview= LayoutInflater.from(context).inflate(R.layout.slide_view,this,true);
        for(int i=0;i<ids.length;i++)
        {
            View item=slideview.findViewById(ids[i]);
            final int temp=i;
            contents[i]=(TextView) item.findViewById(R.id.content);
            contents[i].setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    onSlide(temp);
                }
            });
            slides[i]=item.findViewById(R.id.slide);

        }
    }

    private void onSlide(int i)
    {
        for(int j=0;j<contents.length;j++)
        {
            contents[j].setTextColor(getResources().getColor(R.color.colorPwd));
            slides[j].setVisibility(INVISIBLE);
        }
        contents[i].setTextColor(Color.BLACK);
        slides[i].setVisibility(VISIBLE);
    }

    public void setDatum(String[] datum) {
        if(datum==null||datum.length<ids.length)
            throw new RuntimeException("datum error");
        for(int i=0;i<contents.length;i++)
            contents[i].setText(datum[i]);
        slides[0].setVisibility(VISIBLE);
        contents[0].setTextColor(Color.BLACK);
    }





}

